<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="资产id" prop="assetId">-->
<!--        <el-input-->
<!--          v-model="queryParams.assetId"-->
<!--          placeholder="请输入资产id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="资产领用表id" prop="assetReceiveId">
        <el-input
          v-model="queryParams.assetReceiveId"
          placeholder="请输入资产领用表id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产名称" prop="assetName">
        <el-input
          v-model="queryParams.assetName"
          placeholder="请输入资产名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="资产类别名称" prop="className">-->
<!--        <el-input-->
<!--          v-model="queryParams.className"-->
<!--          placeholder="请输入资产类别名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="品牌" prop="assetBrand">-->
<!--        <el-input-->
<!--          v-model="queryParams.assetBrand"-->
<!--          placeholder="请输入品牌"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="规格型号" prop="assetModel">-->
<!--        <el-input-->
<!--          v-model="queryParams.assetModel"-->
<!--          placeholder="请输入规格型号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="数量" prop="assetQuantity">-->
<!--        <el-input-->
<!--          v-model="queryParams.assetQuantity"-->
<!--          placeholder="请输入数量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="报修人id" prop="repairPerId">-->
<!--        <el-input-->
<!--          v-model="queryParams.repairPerId"-->
<!--          placeholder="请输入报修人id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="报修人" prop="repairPerName">
        <el-input
          v-model="queryParams.repairPerName"
          placeholder="请输入报修人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="报修人部门id" prop="repairPerDeptId">-->
<!--        <el-input-->
<!--          v-model="queryParams.repairPerDeptId"-->
<!--          placeholder="请输入报修人部门id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="报修人部门名称" prop="repairPerDeptName">-->
<!--        <el-input-->
<!--          v-model="queryParams.repairPerDeptName"-->
<!--          placeholder="请输入报修人部门名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="当前使用人id" prop="userId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userId"-->
<!--          placeholder="请输入当前使用人id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="当前使用人姓名" prop="userName">-->
<!--        <el-input-->
<!--          v-model="queryParams.userName"-->
<!--          placeholder="请输入当前使用人姓名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="当前使用人部门id" prop="userDeptId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userDeptId"-->
<!--          placeholder="请输入当前使用人部门id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="当前使用人部门名称" prop="userDeptName">-->
<!--        <el-input-->
<!--          v-model="queryParams.userDeptName"-->
<!--          placeholder="请输入当前使用人部门名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="报修时间" prop="repairTime">
        <el-date-picker clearable
          v-model="queryParams.repairTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择报修时间">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="维修金额" prop="repairMoney">-->
<!--        <el-input-->
<!--          v-model="queryParams.repairMoney"-->
<!--          placeholder="请输入维修金额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="维修时间" prop="upkeepTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.upkeepTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择维修时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="维修人id" prop="respPerId">-->
<!--        <el-input-->
<!--          v-model="queryParams.respPerId"-->
<!--          placeholder="请输入维修人id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="维修人名称" prop="respPerName">-->
<!--        <el-input-->
<!--          v-model="queryParams.respPerName"-->
<!--          placeholder="请输入维修人名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="维修人部门id" prop="respPerDeptId">-->
<!--        <el-input-->
<!--          v-model="queryParams.respPerDeptId"-->
<!--          placeholder="请输入维修人部门id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="维修人部门名称" prop="respPerDeptName">-->
<!--        <el-input-->
<!--          v-model="queryParams.respPerDeptName"-->
<!--          placeholder="请输入维修人部门名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:AssetRepair:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:AssetRepair:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:AssetRepair:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:AssetRepair:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="AssetRepairList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="自增id" align="center" prop="id" />
      <el-table-column label="资产领用表id" align="center" prop="assetReceiveId" />
      <el-table-column label="资产id" align="center" prop="assetId" />
      <el-table-column label="资产名称" align="center" prop="assetName" />
      <el-table-column label="资产类别名称" align="center" prop="className" />
      <el-table-column label="品牌" align="center" prop="assetBrand" />
      <el-table-column label="规格型号" align="center" prop="assetModel" />
      <el-table-column label="数量" align="center" prop="assetQuantity" />
      <el-table-column label="报修人id" align="center" prop="repairPerId" />
      <el-table-column label="报修人姓名" align="center" prop="repairPerName" />
      <el-table-column label="报修人部门id" align="center" prop="repairPerDeptId" />
      <el-table-column label="报修人部门名称" align="center" prop="repairPerDeptName" />
      <el-table-column label="当前使用人id" align="center" prop="userId" />
      <el-table-column label="当前使用人姓名" align="center" prop="userName" />
      <el-table-column label="当前使用人部门id" align="center" prop="userDeptId" />
      <el-table-column label="当前使用人部门名称" align="center" prop="userDeptName" />
      <el-table-column label="报修时间" align="center" prop="repairTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.repairTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="维修金额" align="center" prop="repairMoney" />
      <el-table-column label="维修时间" align="center" prop="upkeepTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.upkeepTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报修状态" align="center" prop="repairStatus" />
      <el-table-column label="维修人id" align="center" prop="respPerId" />
      <el-table-column label="维修人名称" align="center" prop="respPerName" />
      <el-table-column label="维修人部门id" align="center" prop="respPerDeptId" />
      <el-table-column label="维修人部门名称" align="center" prop="respPerDeptName" />
      <el-table-column label="维修结果" align="center" prop="repairResult" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="repairSuccess(scope.row)"
            v-hasPermi="['module:AssetRepair:updateRepairSuccess']"
          >维修成功</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="repairFail(scope.row)"
            v-hasPermi="['module:AssetRepair:updateRepairFail']"
          >维修失败</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:AssetRepair:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:AssetRepair:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改资产报修对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="资产领用表id" prop="assetReceiveId">
          <el-input v-model="form.assetReceiveId" placeholder="请输入资产领用表id" />
        </el-form-item>
        <el-form-item label="资产id" prop="assetId">
          <el-input v-model="form.assetId" placeholder="请输入资产id" />
        </el-form-item>
<!--        <el-form-item label="资产名称" prop="assetName">-->
<!--          <el-input v-model="form.assetName" placeholder="请输入资产名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="资产类别名称" prop="className">-->
<!--          <el-input v-model="form.className" placeholder="请输入资产类别名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="品牌" prop="assetBrand">-->
<!--          <el-input v-model="form.assetBrand" placeholder="请输入品牌" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="规格型号" prop="assetModel">-->
<!--          <el-input v-model="form.assetModel" placeholder="请输入规格型号" />-->
<!--        </el-form-item>-->
        <el-form-item label="数量" prop="assetQuantity">
          <el-input v-model="form.assetQuantity" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="报修人id" prop="repairPerId">
          <el-input v-model="form.repairPerId" placeholder="请输入报修人id" />
        </el-form-item>
        <el-form-item label="报修人姓名" prop="repairPerName">
          <el-input v-model="form.repairPerName" placeholder="请输入报修人姓名" />
        </el-form-item>
<!--        <el-form-item label="报修人部门id" prop="repairPerDeptId">-->
<!--          <el-input v-model="form.repairPerDeptId" placeholder="请输入报修人部门id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="报修人部门名称" prop="repairPerDeptName">-->
<!--          <el-input v-model="form.repairPerDeptName" placeholder="请输入报修人部门名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="当前使用人id" prop="userId">-->
<!--          <el-input v-model="form.userId" placeholder="请输入当前使用人id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="当前使用人姓名" prop="userName">-->
<!--          <el-input v-model="form.userName" placeholder="请输入当前使用人姓名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="当前使用人部门id" prop="userDeptId">-->
<!--          <el-input v-model="form.userDeptId" placeholder="请输入当前使用人部门id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="当前使用人部门名称" prop="userDeptName">-->
<!--          <el-input v-model="form.userDeptName" placeholder="请输入当前使用人部门名称" />-->
<!--        </el-form-item>-->
        <el-form-item label="报修时间" prop="repairTime">
          <el-date-picker clearable
            v-model="form.repairTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报修时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="维修金额" prop="repairMoney">
          <el-input v-model="form.repairMoney" placeholder="请输入维修金额" />
        </el-form-item>
        <el-form-item label="维修时间" prop="upkeepTime">
          <el-date-picker clearable
            v-model="form.upkeepTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择维修时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="维修人id" prop="respPerId">
          <el-input v-model="form.respPerId" placeholder="请输入维修人id" />
        </el-form-item>
        <el-form-item label="维修人名称" prop="respPerName">
          <el-input v-model="form.respPerName" placeholder="请输入维修人名称" />
        </el-form-item>
<!--        <el-form-item label="维修人部门id" prop="respPerDeptId">-->
<!--          <el-input v-model="form.respPerDeptId" placeholder="请输入维修人部门id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="维修人部门名称" prop="respPerDeptName">-->
<!--          <el-input v-model="form.respPerDeptName" placeholder="请输入维修人部门名称" />-->
<!--        </el-form-item>-->
        <el-form-item label="维修结果" prop="repairResult">
          <el-input v-model="form.repairResult" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="删除标志" prop="delFlag">-->
<!--          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAssetRepair, getAssetRepair, delAssetRepair, addAssetRepair, updateAssetRepair,updateRepairSuccess,updateRepairFail } from "@/api/module/AssetRepair";

export default {
  name: "AssetRepair",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产报修表格数据
      AssetRepairList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        assetId: null,
        assetName: null,
        className: null,
        assetBrand: null,
        assetModel: null,
        assetQuantity: null,
        repairPerId: null,
        repairPerName: null,
        repairPerDeptId: null,
        repairPerDeptName: null,
        userId: null,
        userName: null,
        userDeptId: null,
        userDeptName: null,
        repairTime: null,
        repairMoney: null,
        upkeepTime: null,
        repairStatus: null,
        respPerId: null,
        respPerName: null,
        respPerDeptId: null,
        respPerDeptName: null,
        assetReceiveId: null,
        repairResult: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资产报修列表 */
    getList() {
      this.loading = true;
      listAssetRepair(this.queryParams).then(response => {
        this.AssetRepairList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        assetId: null,
        assetName: null,
        className: null,
        assetBrand: null,
        assetModel: null,
        assetQuantity: null,
        repairPerId: null,
        repairPerName: null,
        repairPerDeptId: null,
        repairPerDeptName: null,
        userId: null,
        userName: null,
        userDeptId: null,
        userDeptName: null,
        repairTime: null,
        repairMoney: null,
        upkeepTime: null,
        repairStatus: null,
        respPerId: null,
        respPerName: null,
        respPerDeptId: null,
        respPerDeptName: null,
        remark: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        assetReceiveId: null,
        repairResult: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资产报修";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAssetRepair(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改资产报修";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAssetRepair(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAssetRepair(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除资产报修编号为"' + ids + '"的数据项？').then(function() {
        return delAssetRepair(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/AssetRepair/export', {
        ...this.queryParams
      }, `AssetRepair_${new Date().getTime()}.xlsx`)
    },

    /** 维修成功按钮操作 */
    repairSuccess(val) {
      this.$confirm('确认维修成功？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getRepairSuccess(val)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    async getRepairSuccess(val){
      let res=await updateRepairSuccess(val)
      if(res.code == 200){
        this.getList();
        this.$message({
          type: 'success',
          message: '维修成功!'
        });
      }
    },

    /** 维修失败按钮操作 */
    repairFail(val) {
      this.$confirm('确认维修失败？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getRepairFail(val)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    async getRepairFail(val){
      let res=await updateRepairFail(val)
      if(res.code == 200){
        this.getList();
        this.$message({
          type: 'success',
          message: '维修失败，资产已报废!'
        });
      }
    },

  }
};
</script>
